home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 276-300 / disk_280 / graph / grph.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  133 lines

  1. /*
  2.  *                 GRAPH, Version 1.00 - 4 August 1989
  3.  *
  4.  *            Copyright 1989, David Gay. All Rights Reserved.
  5.  *            This software is freely redistrubatable.
  6.  */
  7.  
  8. /* Routines for handling graphs */
  9. #ifndef GRPH_H
  10. #define GRPH_H
  11.  
  12. #include "list.h"
  13. #include "user/gadgets.h"
  14.  
  15. /* Various string lengths */
  16. #define TITLELEN 80
  17. #define GNAMELEN 20
  18.  
  19. /* Store information on each axis */
  20. struct ax {
  21.     double min, max;
  22.     double ax, cstep; /* Axes positions, ax is the position of this axis on the
  23.  other */
  24.                       /* cstep: interval for ticks */
  25.     int every;        /* Frequency of numbering on ticks */
  26.     int log;          /* log scale ? */
  27. };
  28.  
  29. /* Information on coordinate system */
  30. struct axes {
  31.     struct ax x, y;
  32.     double ratio; /* y / x, NOVAL for none (>0 !!) */
  33.     int polar : 1; /* Not used */
  34.     int ok : 1;
  35. };
  36.  
  37. /* User interface state */
  38. struct state {
  39.     int select_mode : 1;
  40.     int mouse : 1;          /* mouse moves expected */
  41.     double x, y;            /* mouse pos. */
  42.     struct object *current;
  43. };
  44.  
  45. /* All information needed for user interface */
  46. struct io {
  47.     UWORD nextmenu;            /* For menu selections */
  48.     struct RWindow *rw;        /* Currently selected output */
  49.     int dpmx, dpmy;            /* Scale (in dots per meter) of output */
  50.     struct Window *win;        /* Window, and assoc. info */
  51.     WORD oldwidth, oldheight;
  52.     struct Gadget *gadgets;
  53.     struct Menu *menu;
  54.     struct Memory *mem;
  55.     char title[TITLELEN];
  56.     struct TextFont *digits;   /* Font for displaying digits on graph */
  57. };
  58.  
  59. /* A graph, made up from the above components */
  60.  
  61. struct graph {
  62.     node node;
  63.     int ok : 1;
  64.     int saved : 1;
  65.     char name[GNAMELEN];
  66.     struct io io;
  67.     list o_list;  /* List of objects in graph */
  68.     struct axes a;
  69.     struct state s;
  70. };
  71.  
  72. /* Open font name, in pts points (use graph scale). Takes nearest size */
  73. struct TextFont *open_font(struct graph *g, char *name, int pts, int style, int
  74.  flags);
  75. /* Convert size in inches to dots in selected output */
  76. int xinch2dots(struct graph *g, double x);
  77. int yinch2dots(struct graph *g, double y);
  78.  
  79. /* objects */
  80. struct object *add_object(struct graph *g, struct object *o);
  81. void remove_object(struct graph *g, struct object *o);
  82. void select_object(struct graph *g, struct object *o);
  83. void deselect(struct graph *g);
  84.  
  85. /* User has used mouse, do any necessary housekeeping (move, select objects, et
  86. c) */
  87. void mouse_down(struct graph *g, WORD sx, WORD sy);
  88. void mouse_move(struct graph *g, WORD sx, WORD sy);
  89. void mouse_up(struct graph *g, WORD sx, WORD sy);
  90.  
  91. /* Ask user to : */
  92. struct object *choose_object(struct graph *g, char *op); /* Select object by na
  93. me */
  94. void enter_limits(struct graph *g); /* Define coord system */
  95. void enter_axes(struct graph *g);   /* Choose axes display options */
  96.  
  97. /* Change graph: */
  98. int set_dpm(struct graph *g, int dpmx, int dpmy); /* set new scale (in dpm) */
  99. void set_thin(struct graph *g, struct RastPort *rp); /* Use thin lines */
  100. void set_pensize(struct graph *g, struct RastPort *rp, double ptsize); /* Use l
  101. ines ptsize points wide */
  102. void set_mode(struct graph *g, int newmode); /* Select select/point mode */
  103. void set_scale(struct graph *g);      /* Window size has changed */
  104. void zoom_in(struct graph *g, double x0, double y0, double x1, double y1); /* S
  105. et new coord limits */
  106. void zoom_factor(struct graph *g, double factor); /* Zoom in by a factor */
  107. void center_graph(struct graph *g, double x, double y); /* Recenter around poin
  108. t */
  109.  
  110. /* Output routines: */
  111. void draw_graph(struct graph *g, int allow_mes); /* Draw graph */
  112. void refresh_graph(struct graph *g, int allow_mes, struct Region *ref); /* Redr
  113. aw inside region ref only */
  114. struct Region *full_refresh(struct graph *g); /* Return a region covering the w
  115. hole graph */
  116. void set_title(struct graph *g);   /* Change graph title */
  117. void prt_graph(struct graph *g);   /* Output graph to printer */
  118. void iff_todisk(struct graph *g);  /* Output graph as an ILBM file */
  119.  
  120. /* Manipulate graphs : */
  121. struct graph *load_graph(struct graph *from, FILE *f);
  122. int save_graph(struct graph *g, FILE *f);
  123. struct graph *new_graph(struct graph *from); /* from allows you to display mess
  124. ages ... (NULL if none) */
  125. void delete_graph(struct graph *g);
  126.  
  127. /* Global init/cleanup. Must be called */
  128. int init_grph(void);
  129. void cleanup_grph(void);
  130.  
  131. #endif
  132.  
  133.